﻿using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Common.Abstraction;
using Common.Dto;
using Demo03.Domain;
using Demo03.Repository;
using Microsoft.EntityFrameworkCore;

namespace Demo03.Service;

/// <summary>
/// 文章服务
/// </summary>
public class ArticleService : IService
{
    private readonly ArticleRepository _articleRepository;

    /// <summary>
    /// 构造函数
    /// </summary>
    /// <param name="articleRepository"></param>
    public ArticleService(ArticleRepository articleRepository)
    {
        _articleRepository = articleRepository;
    }

    /// <summary>
    /// 查询所有
    /// </summary>
    /// <returns></returns>
    public List<Article> FindAll()
    {
        return _articleRepository.FindAll();
    }

    public async Task<List<int>> TestFindIdList()
    {
        return await _articleRepository.DbContext.Articles.Where(it => it.Id == 1).Select(it => it.Id)
            .ToListAsync();
    }

    public async Task<PageObject<Article>> FindPagedList(PageQuery pageQuery)
    {
        return await _articleRepository.FindPagedListAsync(pageQuery, SortObject.OrderByAsc("Id"));
    }
}